package com.java8.zhangzixiang;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class Demo03 {
  public static void main(String[] args) {
    List<Student> list = new ArrayList<>();
    Student s1 = new Student();
    s1.setId(1);
    s1.setName("kfds");
    s1.setAge(22);
    list.add(s1);

    Student s2 = new Student();
    s1.setId(2);
    s1.setName("ks");
    s1.setAge(24);
    list.add(s2);

    Student s3 = new Student();
    s1.setId(3);
    s1.setName("kfd");
    s1.setAge(21);
    list.add(s3);

    list.forEach(s->s.show());//类名引用方法时，要求必须是函数接口的第一个参数调用方法
    list.forEach(Student::show);
    System.out.println("---");
    list.forEach(s->s1.show2(s));//对象名引用方法时，要求被调用的方法的参数和函数接口的参数类型一致
    list.forEach(s1::show2);

    list.forEach(s-> System.out.println(s));
    list.forEach(System.out::println);

    list.forEach(s->Student.play(s));//类型引用静态方法时，要求被调用的静态方法的参数和函数接口参数一致
    list.forEach(Student::play);

    /*匿名类的方式*/
    GetStudent gs1 = new GetStudent() {
      @Override
      public Student getStu() {
        return new Student();
      }
    };
    Student stu1 = gs1.getStu();
    /*箭头函数方式*/
    GetStudent gs2 = ()->new Student();
    Student stu2=gs2.getStu();
    /*方法引用的方式*/
    GetStudent gs3 = Student::new;
    Student stu3 = gs3.getStu();

    Supplier<Student> supplier = Student::new;
    Student stu4 = supplier.get();

    Supplier<Demo01> sd = Demo01::new;
    Demo01 d1 = sd.get();


  }
}
